< previous page page_460 next page >

Page 460
can use spherical coordinates to easily change the angle of projection without changing the distance from the center of projection to the focus point.
Many of the example programs in this chapter use this method for specifying the center of projection. The distance R is fixed by the program. As the program runs, you can use the right and left arrow keys to increase and decrease the value of q. Similarly, you can use the up and down arrow keys to increase and decrease the value of f.
The m3PProject routine in module M3Ops.bas is similar to subroutine m3Project, except it specifies the center of projection in spherical coordinates. All this routine does is convert the spherical coordinates into Cartesian coordinates and then call m3Project to initialize the transformation matrix.
e10a6a0a59f035e870d90cca05b85fce.gif
' Create a 3-D transformation matrix for a
' perspective projection with:
'       center of projection    (r, phi, theta)
'       focus                   (fx, fy, fx)
'       up vector             <ux, uy, uz>
' ptype should be m3Perspective or m3Parallel.
Public Sub m3PProject(M() As Single, ByVal ptype As Integer, _
    ByVal r As Single, ByVal phi As Single, _
    ByVal theta As Single, ByVal Fx As Single, _
    ByVal Fy As Single, ByVal Fz As Single, _
    ByVal ux As Single, ByVal uy As Single,
    ByVal uz As Single)
Dim cx As Single
Dim cy As Single
Dim cz As Single
Dim r2 As Single

    ' Convert to Cartesian coordinates.
    cy = r * Sin(phi)
    r2 = r * Cos(phi)
    cx = r2 * Cos(theta)
    cz = r2 * Sin(theta)
    m3Project M, ptype, cx, cy, cz, Fx, Fy, Fz, ux, uy, uz
End Sub
Example program Platonic uses subroutine m3PProject to display the five Platonic solids. These solids, the tetrahedron, cube (or hexahedron), octahedron, dodecahedron, and icosahedron, were classified by the Greek philosopher Plato (B.C. 427-347). They are the only three-dimensional solids you can make using regular polygons for sides.
Using check boxes, you can indicate which solids the program should display and whether it should draw the coordinate axes. Click on the drawing area to give it the keyboard focus. Then you can use the arrows to change the values of the center of projection's spherical coordinates f and q.

 
< previous page page_460 next page >